//
//  RecordAudio.h
//  JuuJuu
//
//  Created by xiaoguang huang on 11-12-19.
//  Copyright (c) 2011年 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <AVFoundation/AVFoundation.h>
#import <CoreAudio/CoreAudioTypes.h>
#import "amrFileCodec.h"

typedef NS_ENUM(NSInteger, RecordState) {
    RecordStateStart, //录音开始
    RecordStateStop, //成功
    RecordStateCancel, //取消
    RecordStatePause, //暂停
    RecordStateFail //录音时长小于1秒钟
};
typedef NS_ENUM(NSInteger, AudioPlayState) {
    AudioPlayStateStart, //音频播放开始
    AudioPlayStateStop, //停止
    AudioPlayStatePause, //暂停
    AudioPlayStateComplete, //完成
    AudioPlayStateFail //解码失败
};

@protocol AudioDelegate <NSObject>
@optional
// 录音回调
- (void)recordResult:(RecordState)status andAudioUrlStr:(NSString *)audioUrlStr;
// 播放回调
-(void)audioPlayResult:(AudioPlayState)status;
@end


@interface RecordAudio : NSObject <AVAudioRecorderDelegate,AVAudioPlayerDelegate>
{
    //Variables setup for access in the class:
	NSURL * recordedTmpFile;
	AVAudioRecorder * recorder;
	NSError * error;
    AVAudioPlayer * avPlayer;
}

@property (nonatomic,assign)id<AudioDelegate> delegate;

// start or resume record
- (void)startRecord; //开始录音
- (NSString *)stopRecord; //停止录音
- (void)cancelRecord; //取消录音
- (void)pauseRecord; //暂停录音

#pragma mark 2015-06-09
- (void)playWithAudioUrlStr:(NSString *)audioUrlStr;

// data must be the audio of amr format
- (void)play:(NSData*) data; //播放录音
- (void)stopPlay; //停止录音播放
- (void)pausePlay; //暂停录音播放
// 音频时长
+ (NSTimeInterval)getAudioTime:(NSData *) data;
@end
